package kr.or.kosta.otr.persistence.comment;

import java.sql.SQLException;
import java.util.ArrayList;

import javax.annotation.Resource;

import kr.or.kosta.otr.vo.CommentVO;

import org.springframework.stereotype.Repository;

import com.ibatis.sqlmap.client.SqlMapClient;

@Repository("CommentDao")
public class CommentDaoImpl implements CommentDao{
	@Resource(name="sqlMapClient")
	private SqlMapClient sqlMapClient;

	@Override
	public int writeComment(CommentVO vo) throws SQLException {
		return (int) sqlMapClient.insert("Comment.writeComment", vo);
	}

	@Override
	public void deleteComment(int commentId) throws SQLException {
		sqlMapClient.delete("Comment.deleteComment", commentId);
	}

	@Override
	public void updateComment(CommentVO vo) throws SQLException {
		sqlMapClient.update("Comment.updateComment", vo);
	}

	@Override
	public void updateDepth(int commentId) throws SQLException {
		sqlMapClient.update("Comment.updateDepth", commentId);
	}
	
	@Override
	public void updateStep(CommentVO vo) throws SQLException {
		sqlMapClient.update("Comment.updateStep", vo);
	}
	
	@Override
	public CommentVO getOneComment(int commentId) throws SQLException {
		return (CommentVO) sqlMapClient.queryForObject("Comment.getOneComment", commentId);
	}

	@Override
	public ArrayList<CommentVO> getAGroupOfComments(int boardId) throws SQLException {
		return (ArrayList<CommentVO>) sqlMapClient.queryForList("Comment.getAGroupOfComments", boardId);
	}
	
	@Override
	public int getMaxRef(int boardId) throws SQLException {
		int r=0;
		if(sqlMapClient.queryForObject("Comment.getMaxRef", boardId)!=null){
			r=(int) sqlMapClient.queryForObject("Comment.getMaxRef", boardId);
		}
		return r;
	}

	@Override
	public int getMaxStep(int ref) throws SQLException {
		return (int) sqlMapClient.queryForObject("Comment.getMaxStep", ref);
	}
	
}
